package com.zy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zy.bean.bo.script.LiteflowScriptBo;
import com.zy.bean.po.LiteflowScript;
import com.zy.mapper.LiteflowScriptMapper;
import com.zy.service.LiteflowScriptService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

/**
 * @author hanhuafeng
 * @description 针对表【api_flow_liteflow_script(liteflow编排规则流程表)】的数据库操作Service实现
 * @createDate 2023-11-13 17:06:13
 */
@Service
public class LiteflowScriptServiceImpl extends ServiceImpl<LiteflowScriptMapper, LiteflowScript>
        implements LiteflowScriptService {

    /**
     * 新增liteflow脚本组件
     *
     * @param createBo 新增对象
     * @return 新增结果
     */
    @Override
    public LiteflowScript createNewLiteflowScript(LiteflowScriptBo createBo) {
        String scriptId = createBo.getScriptId();
        if (ObjectUtils.isNotEmpty(scriptId)) {
            LambdaQueryWrapper<LiteflowScript> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(LiteflowScript::getScriptId, scriptId);
            long count = this.count(queryWrapper);
            if (count > 0) {
                throw new RuntimeException("输入的脚本id已存在");
            }
        }
        LiteflowScript liteflowScript = LiteflowScriptBo.toPo(createBo);
        this.save(liteflowScript);
        return liteflowScript;
    }
}




